package com.sinoeyes.common.result;

import lombok.*;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;

/**
 *  业务代码
 *
 * @author aries.hao
 */
@Getter
@Setter
@ToString
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RCode implements Serializable {
    
    private static final long serialVersionUID = 1L;
    /**
     *  code编码
     */
    private String code;
    /**
     *  中文信息描述
     */
    private String message;

    /**
     *  操作数量
     */
    private Integer operateCount;

    private RCode(String code, String message){
        this.code = code;
        this.message = message;
    }

    public RCode(Integer operateCount, String message){
        this.operateCount = operateCount;
        this.message = message;
    }

    public static final RCode IS_NULL = new RCode("0", "NULL");

    /**
     *  操作成功
     */
    public static final RCode SUCCESS = new RCode("1000", "操作成功");

    /**
     *  业务异常
     */
    public static final RCode FAILURE = new RCode("40004", "业务异常");

    /**
     *  参数校验失败
     */
    public static final RCode PARAM_VALID_ERROR = new RCode("10004", "参数校验失败");

    /**
     *  参数校验失败
     */
    public static final RCode PARAM_VALID_ERROR_NO_MSG = new RCode("10005", "");

    /**
     *  请求未授权
     */
    public static final RCode UN_AUTHORIZED = new RCode("60003", "请求未授权");

    /**
     *  请求被拒绝
     */
    public static final RCode REQ_REJECT = new RCode("70001", "请求被拒绝");

    /**
     *  服务器异常
     */
    public static final RCode INTERNAL_SERVER_ERROR = new RCode("40001", "服务器异常");

    /**
     *  缺少必要的请求参数
     */
    public static final RCode PARAM_MISS = new RCode("10002", "缺少必要的请求参数");

    /**
     *  请求参数类型错误
     */
    public static final RCode PARAM_TYPE_ERROR = new RCode("10003", "请求参数类型错误");

    /**
     *  404 没找到请求
     */
    public static final RCode NOT_FOUND = new RCode(HttpServletResponse.SC_NOT_FOUND + "", "404 没找到请求%name%");

    /**
     *  消息不能读取
     */
    public static final RCode MSG_NOT_READABLE = new RCode(HttpServletResponse.SC_BAD_REQUEST + "", "消息不能读取");

    /**
     *  不支持当前请求方法
     */
    public static final RCode METHOD_NOT_SUPPORTED = new RCode(HttpServletResponse.SC_METHOD_NOT_ALLOWED + "", "不支持当前请求方法");

    /**
     *  不支持当前媒体类型
     */
    public static final RCode MEDIA_TYPE_NOT_SUPPORTED = new RCode(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE + "", "不支持当前媒体类型");

    /**
     *  请求参数绑定错误
     */
    public static final RCode PARAM_BIND_ERROR = new RCode(HttpServletResponse.SC_BAD_REQUEST + "", "请求参数绑定错误");

    /**
     *  请求返回结果为空
     */
    public static final RCode PARAM_TYPE_RESULT_EMPTY = new RCode(HttpServletResponse.SC_NO_CONTENT + "", "请求返回结果为空");

    /**
     *  修改返回请求参数有误
     */
    public static final RCode IMPORT_ERROR = new RCode(0, "传入参数有误");

    /**
     *  修改返回请求未查询到相关信息
     */
    public static final RCode NO_QUERY = new RCode(0, "未查询到相关信息");

    /**
     *  修改返回请求发布生效
     */
    public static final RCode HAS_VALUE = new RCode(0, "已发布生效，不可删除");

    /**
     * 创建独立说明项，扩展
     * @param code
     * @param message
     * @return RCode
     */
    public static RCode valueOf(String code, String message) {
        return new RCode(code, message);
    }
}

